#define  _CRT_SECURE_NO_WARNINGS
class Solution {
    int dx[4] = { 0, 0, 1, -1 };
    int dy[4] = { 1, -1, 0, 0 };
public:
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
        queue<pair<int, int>> q;
        q.push({ sr, sc });
        int oc = image[sr][sc];
        if (color == oc) return image;
        while (q.size())
        {
            auto [r, c] = q.front(); q.pop();
            image[r][c] = color;
            for (int i = 0; i < 4; i++)
            {
                int x = r + dx[i];
                int y = c + dy[i];
                if (x >= 0 && y >= 0 && x < image.size() && y < image[0].size() && image[x][y] == oc)
                    q.push({ x, y });
            }
        }
        return image;
    }
};